﻿using Microsoft.AspNetCore.Mvc;
using TR.AppService.Dto;
using TR.Domain.Entity.BsItemType;
using TR.Domain.Entity;
using TR.Domain.Repository.sqlDto;
using TR.AppService.AppService.Bs_Item;

namespace TR.WebApi.Controllers.Bs_ItemControllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class BsItemController : ControllerBase
    {
        private readonly IBs_ItemService iitemAppService;
        public BsItemController(IBs_ItemService iitemAppService)
        {
            this.iitemAppService = iitemAppService;
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <returns></returns>
        //[Authorize]
        [HttpGet]
        public async Task<List<bs_Item>> ItemSelect()
        {
            ControllerContext.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
            Console.WriteLine("ItemSelect--->");
            return await iitemAppService.ItemSelete();
        }
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="addItemCsDto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<bool> ItemAdd(bs_Item addItemDto)
        {
            ControllerContext.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
            Console.WriteLine("ItemAdd--->");
            return await iitemAppService.ItemAdd(addItemDto);
        }
        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="pageSize"></param>
        /// <param name="currentPage"></param>
        /// <param name="str"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<FenYe<bs_Item>> bs_Item_FenYe(int pageSize, int currentPage, string str)
        {
            ControllerContext.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
            return await iitemAppService.bs_Item_FenYe(pageSize, currentPage, str);
        }
        /// <summary>
        /// 新增查询
        /// </summary>
        /// <param name="pageSize"></param>
        /// <param name="currentPage"></param>
        /// <param name="str"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<FenYe<bs_Item>> bs_Item_xz_FenYe(int pageSize, int currentPage, string str)
        {
            ControllerContext.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
            return await iitemAppService.bs_Item_xz_FenYe(pageSize, currentPage, str);
        }
        /// <summary>
        /// wh_Orderbuy_d_FenYe
        /// </summary>
        /// <param name="pageSize"></param>
        /// <param name="currentPage"></param>
        /// <param name="str"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<FenYe<wh_orderbuy_d>> wh_Orderbuy_d_FenYe(int pageSize, int currentPage, string str)
        {
            ControllerContext.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
            return await iitemAppService.wh_Orderbuy_d_FenYe(pageSize, currentPage, str);
        }
        /// <summary>
        /// 逻辑删除
        /// </summary>
        /// <param name="item_code"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<bool> ItemUDelect(string item_code)
        {
            ControllerContext.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
            Console.WriteLine("ItemUDelect--->");
            return await iitemAppService.ItemUDelect(item_code);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<bool> ItemDelect(int id)
        {
            ControllerContext.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
            Console.WriteLine("ItemDelect--->");
            return await iitemAppService.ItemDelect(id);
        }
        /// <summary>
        /// 查询id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<bs_Item> ItemSelectid(int id)
        {
            ControllerContext.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
            Console.WriteLine("ItemTypeSelectid--->");
            return iitemAppService.ItemSelectid(id);
        }

        [HttpGet]
        public Task<bs_Item> ItemSelectCode(string item_code)
        {
            ControllerContext.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
            Console.WriteLine("ItemSelectCode--->");
            return iitemAppService.ItemSelectCode(item_code);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="usd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<bool> ItemUpdate(UpdateItemDto uid)
        {
            ControllerContext.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
            Console.WriteLine("ItemTypeUpdate--->");
            return await iitemAppService.ItemUpdate(uid);
        }
    }
}
